package com.youme.section.shop.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.hyphenate.easeim.R
import com.salton123.app.BaseApplication
import com.youme.model.Food
import com.youme.section.shop.ShopDetailsActivity
import kotlinx.android.synthetic.main.item_shop_hot_food.view.*

class HotCaiAdapter(private val data: MutableList<Food>, private val context: Context) :
    RecyclerView.Adapter<HotCaiAdapter.MyViewHolder>() {

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_shop_hot_food, parent, false)
        return MyViewHolder(view)
    }

    override fun getItemCount(): Int {
        return data.size
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val textpos = data[position]

        holder.itemView.iv_add_shopping_cart.text = "¥" + textpos.price
        holder.itemView.tv_goods_name.text = textpos.name
        holder.itemView.tv_sku.text = "店名：" + textpos.restName
        holder.itemView.tv_goods_price.text = "热度：" + textpos.popularity
        Glide.with(BaseApplication.sInstance)
            .load(textpos.icon).into(holder.iv_goods)
        holder.itemView.hot_food_lay.setOnClickListener {
            val intent = Intent()
            intent.putExtra("restId", textpos.restId)
            intent.setClass(context, ShopDetailsActivity().javaClass)
            context.startActivity(intent)
        }
    }

    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val iv_goods: ImageView = itemView.findViewById(R.id.iv_goods)
    }
}